package org.come.MountShouHu;

import com.tool.image.ImageMixDeal;
import com.tool.tcpimg.UIUtils;
import org.come.entity.Mount;
import org.come.until.UserMessUntil;
import org.come.until.Util;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MyMountRenderer extends JPanel implements ListCellRenderer{
    private int index;
    public static String vs;
    public static int  select=-1;
    public MyMountRenderer(final int index) {
        this.index = 67;
        this.index = index;
    }
    public MyMountRenderer() {
        this.index = 67;
    }
    @Override
    public Dimension getPreferredSize() {
        return new Dimension(this.getWidth()/2 , 28);
    }
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        final MyMountRenderer mr = new MyMountRenderer(index);
        mr.removeAll();
        if (xuanzeJpanel.idx == index || isSelected) {
            mr.setBackground(Color.GRAY);
            select=index;
        }
        else {
            mr.setOpaque(false);
        }
        mr.setLayout(new FlowLayout(0));
        final Box box = Box.createHorizontalBox();
        box.add(new JLabel() {
            {
                this.setForeground(Color.BLACK);
                this.setText("");
                try {
                    if (ImageMixDeal.userimg.getRoleShow().getFighting() != 0) {
                        final Map<String, Integer> map = new HashMap<String, Integer>() {
                            {
                                final Iterator<Mount> iterator = UserMessUntil.getMountlsit().listIterator();
                                while (iterator.hasNext()) {
                                    final Mount roleSummoning = iterator.next();
                                  //  final Iterator<TypeState> iterator2 = data.iterator();
                                 /*   while (iterator2.hasNext())*/ {
                                      //  final TypeState datum = (TypeState)iterator2.next();
                                      /*  if (datum.getType().equals(roleSummoning.getSid().toString()))*/ {
                                            this.put(roleSummoning.getMountname(), roleSummoning.getMid().intValue());
                                        }
                                    }
                                }
                                if (isSelected){
                                    mr.setBackground(Color.GRAY);
                                }else mr.setBackground(Color.black);

                            }
                        };

                    }
                }
                catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        mr.add((Component)box);
        return (Component)mr;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        final Graphics2D g2d = (Graphics2D)g;
        g2d.setColor(Color.green);
        g2d.setFont(UIUtils.TEXT_NAME_FONT15);
        String name=UserMessUntil.getMountlsit().get(index).getMountname();
        switch (Util.getSexSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())){
            case "男":
            case "女":
                switch (Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())){
                    case "人":
                    case "魔":
                    case "龙":
                    case "仙":
                    case "鬼":
                        if (name.contains("四")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"4.png").getImage(),0,0,26,26,null);
                        }else if (name.contains("一")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"1.png").getImage(),0,0,26,26,null);
                        }else if (name.contains("二")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"2.png").getImage(),0,0,26,26,null);
                        }else if (name.contains("三")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"3.png").getImage(),0,0,26,26,null);
                        }else if (name.contains("五")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"5.png").getImage(),0,0,26,26,null);
                        }else if (name.contains("六")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"6.png").getImage(),0,0,26,26,null);
                        }else if (name.contains("七")){
                            g2d.drawImage(new ImageIcon("inkImg/Client/zqhead/26x26_"+Util.getRaceSting(ImageMixDeal.userimg.getRoleShow().getSpecies_id())+"7.png").getImage(),0,0,26,26,null);
                        }
                        break;
                }
                break;
        }
        g2d.drawString(MyMountRenderer.vs = UserMessUntil.getMountlsit().get(index).getMountname(), 30, 20);
    }
}
